package com.harvest.scientific.ladder.ext

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import androidx.fragment.app.FragmentActivity

fun Context?.getActivity(): Activity?{
    var context = this
    while (context !is Activity && context is ContextWrapper) {
        context = context.baseContext
    }

    if (context is Activity) {
        return context
    }
    return null
}

fun Context?.getFragmentActivity(context: Context?): FragmentActivity?{
    val activity = context.getActivity()
    if (activity is FragmentActivity){
        return activity
    }
    return null
}